﻿
namespace TinyMceWrapper.Web.UI.WebControls
{

    #region [ Imports ]

    using System.Collections.Specialized;
    using System.ComponentModel;
    using System.Configuration;
    using System.Web.UI.Design;
    using TinyMceWrapper.Web.Configuration;

    #endregion

    public class DisplayModesConverter : TypeConverter
    {

        #region [ Overriden Members ]

        public override bool GetStandardValuesSupported(ITypeDescriptorContext context)
        {
            return (context != null);
        }

        public override bool GetStandardValuesExclusive(ITypeDescriptorContext context)
        {
            return true;
        }

        public override StandardValuesCollection GetStandardValues(ITypeDescriptorContext context)
        {
            StringCollection values = new StringCollection();

            if (context != null)
            {
                IWebApplication webapp = context.GetService(typeof(IWebApplication)) as IWebApplication;
                if (webapp != null)
                {
                    Configuration config = webapp.OpenWebConfiguration(true);
                    if (config != null)
                    {
                        TinyMceSection section = config.GetSection("tinymce") as TinyMceSection;
                        if (section != null)
                            foreach (TinyMceDisplayMode item in section.DisplayModes) values.Add(item.Name);
                    }
                }
            }

            return new StandardValuesCollection(values);
        }

        #endregion

    }

}
